function loadData(toDate) {
    var index = layer.load(1);
    $.get('getGroupTaskMsg', {date: toDate}, function (back) {
        var center = $(".center");

        center.empty();

        $.each(back, function (i, e) {
            if (e.evaluateMsg === undefined) e.evaluateMsg = '';
            var content = '<div class="layui-card">' +
                '                <div class="layui-card-header">' + e.name + ' ' + e.project + ' ' + e.date + '</div>' +
                '                <div class="layui-card-body">' +
                '                    <table class="layui-table">' +
                '                        <colgroup>' +
                '                            <col width="100">' +
                '                            <col width="400">' +
                '                            <col width="400">' +
                '                            <col width="100">' +
                '                        </colgroup>' +
                '                        <thead>' +
                '                        <tr>' +
                '                            <th>姓名</th>' +
                '                            <th>任务</th>' +
                '                            <th>完成情况</th>' +
                '                            <th>完成度</th>' +
                '                        </tr>' +
                '                        </thead>' +
                '                        <tbody>';

            $.each(e.groupMemberTask, function (j, el) {
                content += '                <tr>' +
                    '                        <td>' + el.name + '</td>' +
                    '                        <td>' + el.task + '</td>' +
                    '                        <td>' + el.report + '</td>' +
                    '                        <td>' + el.process + '%</td>' +
                    '                     </tr>'
            });
            content += '              </tbody>' +
                '                    </table>' +
                '                    <div class="layui-row">' +
                '                        <div class="layui-col-md11">' +
                '                            <input type="text" name="evaluate" value="' + e.evaluateMsg + '" placeholder="对' + e.name + '今日进度进行评价" autocomplete="off" class="layui-input">' +
                '                        </div>' +
                '                        <div class="layui-col-md1">' +
                '                            <button type="button" class="layui-btn" name="' + e.pid + '*' + e.date + '">评价</button>' +
                '                        </div>' +
                '                    </div>' +
                '                </div>' +
                '            </div>';
            center.append(content)
        })

        layer.close(index);

        $('.layui-btn').click(function (data) {

            let split = data.target.name.split('*');
            let id = split[0];
            let date = split[1];
            let msg = $(this).parent().prev().children('input').val();
            console.log('项目编号为：' + id + '，在' + date + '的老师评价为:' + msg);
            if (msg === '') {
                layer.msg('老师多少写点吧！', {icon: 5})
            } else {
                $.get('evaluate', {id: id, date: date, evaluate: msg}, function (back) {
                    layer.msg('评价成功，老师辛苦了！', {icon: 6})
                })
            }

        });
    });
}

// 初始加载数据
loadData();

function getCurrentDate(date) {
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    var d = date.getDate();
    return y + '-' + (m < 10 ? ('0' + m) : m) + '-' + (d < 10 ? ('0' + d) : d);
}

// 当前时间毫秒数
var date = new Date().getTime();

// 上一天
$('.upDown:nth-child(1)').click(function () {
    date -= (1000 * 60 * 60 * 24);
    loadData(getCurrentDate(new Date(date)));
});

// 下一天
$('.upDown:nth-child(3)').click(function () {
    date += (1000 * 60 * 60 * 24);
    loadData(getCurrentDate(new Date(date)));
});

